<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'query.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript"
	src="http://api.map.baidu.com/api?v=2.0&ak=gkhZkvMMhPRMs1ybtbM7nmhH1ryHr6Dp"></script>
<title>机构资源信息查询系统</title>
<script type="text/javascript" src="static/js/jquery.min.js"></script>
</head>

<body>
	<div style="width:730px;margin:auto;">
		机构名称： <input id="name" type="text" value="" /> <span id="tip"
			style="color:red"></span> <input type="button" value="查询"
			onclick="searchByInstrumentName();" />
		<div id="container"
			style="position: absolute;
                margin-top:30px;
                width: 730px;
                height: 560px;
                top: 50;
                border: 1px solid gray;
                overflow:hidden;">
		</div>
	</div>
</body>
<script type="text/javascript">
	var map = new BMap.Map("container");
	map.centerAndZoom("伊春", 6);
	map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
	map.enableContinuousZoom(); //启用地图惯性拖拽，默认禁用

	map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件
	// 	map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件
	// 	map.addControl(new BMap.OverviewMapControl({
	// 		isOpen : true,
	// 		anchor : BMAP_ANCHOR_BOTTOM_RIGHT
	// 	})); //右下角，打开


	function searchByInstrumentName() {
		map.clearOverlays();
		map.centerAndZoom("伊春", 6);
		$("#tip").html("");
		var data = $("#name").val();
		if (data == "" || data == null) {
			$("#tip").html("请填写要查询的机构名称");
			//alert("请填写要查询的仪器名称");
			return;
		}
		$.ajax({
			type : 'GET',
			url : 'institution/getQuery.ins',
			data : "name=" + data,
			dataType : "json",
			success : function(data) {
				if (data != null) {
					if (JSON.stringify(data) == "[]") {
						alert("无查询结果,请换一个关键词!");
					} else {
						for (var i = 0; i < data.length; i++) {
							var marker = new BMap.Marker(new BMap.Point(data[i].lng, data[i].lat));
							var content = "";
							for (var j = 0; j < data[i].info.length; j++) {
								content += "code : " + data[i].info[j].code + "<br/>name:" + data[i].info[j].name +
									"<br/><a href=\"institution/detail.ins?code=" + data[i].info[j].code + "\">机构详情</a>" +
									"<br/><a onclick=\"getInstrument(" + data[i].info[j].code + ",\'" + data[i].info[j].name + "\');\">机构详情</a><br/>";
							}
							map.addOverlay(marker);
							(function(i) {
								var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>" + content + "</p>");
								marker.addEventListener("mouseover", function() {
									this.openInfoWindow(infoWindow);
								})
							})(i);
						}
					}
				}
			},
			error : function(data) {
				alert("网络连接中断，请检查网络！");
			}
		})
	}
</script>
</html>
